<?php
namespace Admin\Controller;
use Think\Controller;
class FenleiController extends myController{
	public function index(){
		$model=D('Fenlei');
		$arr=$model->where("pid=0")->select();
		$arr1=$model->where("pid != 0")->select();
		$this->assign('arr',$arr);
		$this->assign('arr1',$arr1);
		$this->display('index');
	}
	//添加
	public function add(){
		$this->display('add');
	}
	public function addok(){
		if(IS_POST){
			$model=D('Fenlei');
			$pid=I('post.pid');
			if($model->create()){
			
				if($data=$model->add()){
					$this->success('添加成功',U('index',array('id'=>$data['id'])),2);
				}else{
					$this->error('添加失败',U('add'),1);
				}
			}else{
				$this->error('创建失败',U('add'),1);
			}
			
		}
	}
	//编辑
	public function edit(){
		$model=D('Fenlei');
		$id=(int)$_GET['id'];
		$data=$model->find($id);
		$this->assign('data',$data);
		$this->display('edit');
	}
	public function editok(){
		if(IS_POST){
			$model=D('Fenlei');
			if($model->create()){
				if($data=$model->save()){
					$this->success('编辑成功',U('index',array('id'=>$data['id'])),2);
				}else{
					$this->error('编辑失败',U('edit'),1);
				}
			}else{
				$this->error('创建失败',U('edit'),1);
			}
		}
	}
	//删除
	public function delete(){
		if(IS_POST){
			
		}
	}
}